import axios from 'axios'

const request = axios.create({
	timeout: 5000
})

request.interceptors.request.use(config => {
	config.headers!['token'] = localStorage.getItem('token') || ''
	return config
}, error => {
	return Promise.reject(error)
})

request.interceptors.response.use(response => {
	const { code } = response.data
	switch (code) {
		case 403:
			console.log('没有权限');
			break;
		case 401:
			console.log('没有携带token');
			break;
		case 500:
			console.log('服务端错误');
			break;
		case 503:
			console.log('服务端错误');
			break;
	}
	return response
}, error => {
	return Promise.reject(error)
})


export default request